package com.hqyj.shop.controller;

import com.hqyj.shop.dao.UserMessageDao;
import com.hqyj.shop.pojo.Detail;
import com.hqyj.shop.pojo.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@Controller
@RequestMapping("/userMessage")
public class UserMessageController {

    @Autowired
    private UserMessageDao userMessageDao;

    @RequestMapping("/getUser")
    public String getAllUserByPage(ModelMap modelMap){
        //调用服务层返回模型数据
        List<User> pageData = userMessageDao.queryAllByUserId();
        //给视图传递上下文参数
        modelMap.put("Users", pageData);
        //请求转发到success.jsp
        return "userMessage";
    }

    @RequestMapping("/deleteOne")
    public String deleteOneByPage(int userId){
        try {
            userMessageDao.deleteByUserId(userId);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return "redirect:/userMessage/getUser";
    }


}
